import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import { store } from './store';
import { directive } from '@/utils/directive';
import other from '@/utils/other';

import ElementPlus from 'element-plus';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import 'element-plus/dist/index.css';
import '@/theme/index.scss';
import mitt from 'mitt';
import {FastCrud} from "@fast-crud/fast-crud";
import "@fast-crud/fast-crud/dist/style.css";
import ui from "@fast-crud/ui-element";


import { registerUI } from '@/plugins/bin-ui-next'
import { registerCharts } from '@/plugins/bin-charts-next'
import { registerEditor } from '@/plugins/bin-editor-next'
import { registerDatav } from '@/plugins/bin-datav'
import { registerVCharts } from '@/components/Schema'
import { registerGUI } from '@/components/Schema/ui'
import 'bin-ui-next/lib/styles/normalize.css' // 初始化样式
import 'bin-ui-next/lib/styles/scrollbar.css' // 滚动条样式
import 'bin-ui-next/lib/styles/index.css' // 组件库样式
import 'bin-datav/lib/styles/index.css'
import '@/assets/stylus/index.scss' // 项目样式

const app = createApp(App);

registerUI(app)
registerCharts(app)
registerEditor(app)
registerDatav(app)
registerVCharts(app)
registerGUI(app)
directive(app);
other.elSvg(app);
app.use(ui);
app.use(FastCrud, {
    // 此处配置公共的dictRequest（字典请求）
    async dictRequest({ dict }) {
        return await request({ url: dict.url }); //根据dict的url，异步返回一个字典数组
    },
    //公共crud配置
    commonOptions() {
        return {
            request:{
                //接口请求配置
                //你项目后台接口大概率与fast-crud所需要的返回结构不一致，所以需要配置此项
                //请参考文档http://fast-crud.docmirror.cn/api/crud-options/request.html
                transformQuery: ({ page, form, sort }) => {
                    //转换为你pageRequest所需要的请求参数结构
                    return {page, form, sort};
                },
                transformRes: ({ res }) => {
                    //将pageRequest的返回数据，转换为fast-crud所需要的格式
                    return {
                        records:res.data,
                        currentPage:res.current_page,
                        pageSize:res.per_page,
                        total:res.total
                    };
                }
            }
        };
    },
});
app.use(router).use(store).use(ElementPlus, { size: other.globalComponentSize, locale: zhCn }).mount('#app');

app.config.globalProperties.mittBus = mitt();
